package su.kozhevnikov.nookbrary;

import java.util.List;

import su.kozhevnikov.nookbrary.items.SettingsListItem;

import su.kozhevnikov.nookbrary.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListWithDescriptionAdapter extends BaseAdapter {
	protected List<SettingsListItem> items;
	protected LayoutInflater inflater;
	
	public ListWithDescriptionAdapter(Context context, int textViewResourseID, List<SettingsListItem> items) {
		this.items = items;
		this.inflater = LayoutInflater.from(context);
	}
	
	public int getCount() {
		// TODO Auto-generated method stub
		return this.items.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.items.get(arg0);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.list_item_detail,null);
			holder = new ViewHolder();
			holder.list_item_title = (TextView) convertView.findViewById(R.id.list_item_title);
			holder.list_item_description = (TextView) convertView.findViewById(R.id.list_item_description);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.list_item_title.setText(this.items.get(position).getTitle());
		holder.list_item_description.setText("(" + this.items.get(position).getCount() + ")");
		return convertView;
	}
	
	static class ViewHolder {
		TextView list_item_title;
		TextView list_item_description;
	}

}
